//
//  SINAMoneyViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2017/12/1.
//  Copyright © 2017年  androidlongs. All rights reserved.
//

#import "SINAMoneyViewController.h"
#import "SINAMoneyModel.h"
#import "SINAMoneyTableViewCell.h"

@interface SINAMoneyViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property(nonatomic,strong) NSMutableArray *dataList;

@end

@implementation SINAMoneyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title =@"资金发放记录";
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    self.navigationController.navigationBar.barTintColor = [UIColor whiteColor];
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
    self.tableView.delegate=self;
    self.tableView.dataSource=self;
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.navigationItem.leftBarButtonItems = @[leftItem];
    // Do any additional setup after loading the view from its nib.
    
    [self loadingNetDatasFunction];
}
-(void) backAction{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(NSMutableArray *)dataList{
    if (!_dataList) {
        _dataList = [NSMutableArray array];
    }
    return  _dataList;
}
-(void)loadingNetDatasFunction{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *userId = [defaults objectForKey:@"userId"];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setObject:@"1" forKey:@"pageIndex"];
    [dict setObject:@"500" forKey:@"pageSize"];
    [dict setObject:userId forKey:@"userId"];
    [CXAFNHttpRequestUtils httpPostRequest:[NSString stringWithFormat:@"%@%@",baseUrl,getAllMoneyUrl] withParamters:dict success:^(id responseData) {
        NSArray *datas = responseData[@"Data"];
        
        for (NSInteger i=0; i<datas.count; i++) {
            [self.dataList addObject:[SINAMoneyModel moneyWithDict:datas[i]]];
        }
        
        [self.tableView reloadData];
        
    } failure:^(NSError *error, NSInteger errCode) {
        DLog(@"加载 失败");
    }];
    
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataList.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SINAMoneyModel *itemModel  = self.dataList[indexPath.row];
    SINAMoneyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SINAMoneyTableViewCell"];
    
    if (cell == nil) {
        cell= [[[NSBundle mainBundle]loadNibNamed:@"SINAMoneyTableViewCell" owner:nil options:nil] firstObject];
        //        cell = [[MonitorHistoryTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MonitorHistoryTableViewCell"];
    }
    [cell setMoneyModel:itemModel];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell ;
    
}
//-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
//    return 180;
//}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
    NSInteger index = indexPath.row;
    DLog(@"click .... %ld",(long)index);
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
